/*******************************************************************************
 * Copyright (c) 2001, 2002 Boris Pruessmann and others. All rights reserved.
 * This program and the accompanying materials are made available under the
 * terms of the Common Public License v0.5 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/cpl-v05.html
 * 
 * Contributors: Boris Pruessmann - Initial implementation.
 ******************************************************************************/
package net.sourceforge.perforce.ui;

import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;

/**
 * @version $Revision: 488 $
 * @author <a href="mailto:bpruessmann@users.sourceforge.net">Boris
 *         Pruessmann</a>
 */
class DecorationSettings implements IPropertyChangeListener {
  // ---------------------------------------------------------------------------
  // Private Variables

  /** Indicates whether the 'has remote' decoration will be performed. */
  static public boolean indicateHasRemote;

  /** Indicates whether the 'no remote' decoration will be performed. */
  static public boolean indicateNewResource;

  /** Indicates whether the 'opened by other' decoration will be performed. */
  static public boolean indicateOpenedByOther;

  /** Indicates whether the 'opened for add' decoration will be performed. */
  static public boolean indicateOpenedForAdd;

  /** Indicates whether the 'opened for edit' decoration will be performed. */
  static public boolean indicateOpenedForEdit;

  // -------------------------------------------------------------------------
  // Public Constructors

  /**
   * Constructor for DecorationSettings.
   */
  public DecorationSettings() {
    IPreferenceStore store = PerforceUIPlugin.getPlugin().getPreferenceStore();
    store.addPropertyChangeListener(this);

    indicateHasRemote = store.getBoolean(IPerforceUIConstants.PREF_INDICATE_HAS_REMOTE);
    indicateNewResource = store.getBoolean(IPerforceUIConstants.PREF_INDICATE_NEW_RESOURCE);
    indicateOpenedByOther = store.getBoolean(IPerforceUIConstants.PREF_INDICATE_OPENED_BY_OTHER);
    indicateOpenedForAdd = store.getBoolean(IPerforceUIConstants.PREF_INDICATE_OPENED_FOR_ADD);
    indicateOpenedForEdit = store.getBoolean(IPerforceUIConstants.PREF_INDICATE_OPENED_FOR_EDIT);
  }

  //----------------------------------------------------------------------------
  // -- Public Methods
  /** @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(PropertyChangeEvent) */
  public void propertyChange(PropertyChangeEvent event) {
    String property = event.getProperty();
    if (property.equals(IPerforceUIConstants.PREF_INDICATE_HAS_REMOTE)) {
      indicateHasRemote = ((Boolean) event.getNewValue()).booleanValue();
    } else if (property.equals(IPerforceUIConstants.PREF_INDICATE_NEW_RESOURCE)) {
      indicateNewResource = ((Boolean) event.getNewValue()).booleanValue();
    } else if (property.equals(IPerforceUIConstants.PREF_INDICATE_OPENED_BY_OTHER)) {
      indicateOpenedByOther = ((Boolean) event.getNewValue()).booleanValue();
    } else if (property.equals(IPerforceUIConstants.PREF_INDICATE_OPENED_FOR_ADD)) {
      indicateOpenedForAdd = ((Boolean) event.getNewValue()).booleanValue();
    } else if (property.equals(IPerforceUIConstants.PREF_INDICATE_OPENED_FOR_EDIT)) {
      indicateOpenedForEdit = ((Boolean) event.getNewValue()).booleanValue();
    }
  }
}
